package com.wangdong.rxjavaandroid;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.wangdong.rxjavaandroid.javaobserver.demo1.IStudent;
import com.wangdong.rxjavaandroid.javaobserver.demo1.Student;
import com.wangdong.rxjavaandroid.javaobserver.demo1.Teacher;
import com.wangdong.rxjavaandroid.javaobserver.demo2.Student$Observer;
import com.wangdong.rxjavaandroid.javaobserver.demo2.Student$Observer1;
import com.wangdong.rxjavaandroid.javaobserver.demo2.Student$Observer2;
import com.wangdong.rxjavaandroid.javaobserver.demo2.Teacher$Observable;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);






    }

    public static void main(String[] args) {
        /**
         * 首先说明一下,观察者模式
         * 例子: 老师和学生 ,电话, 学生给老师打电话, 如果老师电话号码修改了 学生第一时间知道
         */
        //创建老师
        Teacher teacher = new Teacher();

        //创建多名学生
        IStudent xiaoming = new Student().setName("小明");
        IStudent xiaohua = new Student().setName("小花");
        IStudent xiaoliu = new Student().setName("小刘");
        IStudent xiaotian = new Student().setName("小田");
        IStudent xiaowang = new Student().setName("小王");
        //绑定每个观察者学生
        teacher.addObserver(xiaohua);
        teacher.addObserver(xiaoliu);
        teacher.addObserver(xiaoming);
        teacher.addObserver(xiaotian);
        teacher.addObserver(xiaowang);
        //老师电话号码修改了, 通知大家
        teacher.setTeacherNum("119");
        /**
         *  说一说 java中的观察者
         *  使用java.util.Observer和.Observable 实现观察者
         */
        Teacher$Observable teacher$Observable = new Teacher$Observable();
        //创建学生实例
        Student$Observer student$Observer = new Student$Observer();
        Student$Observer1 student$Observer1 = new Student$Observer1();
        Student$Observer2 student$Observer2 = new Student$Observer2();
        //订阅,绑定
        teacher$Observable.addObserver(student$Observer);
        teacher$Observable.addObserver(student$Observer1);
        teacher$Observable.addObserver(student$Observer2);
        //老师电话号码修改.通知大家
        teacher$Observable.setTeacherNum("119");

    }
}
